﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Assignment1
{
    public partial class _Default : System.Web.UI.Page
    {
        GuestBookDataContext ctx = new GuestBookDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetBind();
            }


        }
        protected void btn_SendMessage_Click(object sender, EventArgs e)
        {
            GuestBook gb = new GuestBook();
            gb.ID = Guid.NewGuid();
            gb.UserName = tb_UserName.Text;
            gb.Message = tb_Message.Text;
            gb.IsReplied = false;
            gb.PostTime = DateTime.Now;
            ctx.GuestBook.InsertOnSubmit(gb);
            ctx.SubmitChanges();
            SetBind();
        }
        private void SetBind()
        {
            rpt_Message.DataSource = from gb in ctx.GuestBook orderby gb.PostTime descending select gb;
            rpt_Message.DataBind();
        }

    }
}
